/**
 * Created by hcadmin on 16/6/14.
 */
var Action = require("../apiaction");

exports.userAPI = function(router) {

    //用户列表
    router.all('/api/userslist',function(req,res){
        var page = req.param("page");
        var rows = req.param("rows");
        var mobile = req.param("mobile");
        var vip = req.param("vip");

        var params = {
            page:page,
            rows:rows,
            mobile:mobile,
            vip:vip,
            method:'GET'
        };
        console.log(params);
        Action.send(req,res,'users/list',params,function(res,data){

            var json=JSON.parse(data);
            // console.log(json.data);

            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    });

    //用户详情
    router.all('/api/users',function(req,res){

        var id = req.param("id");
        var params = {
            id:id,
            method:'GET'
        };

        Action.send(req,res,'users/'+id,params,function(res,data){

            var json=JSON.parse(data);

            //console.log(json);

            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    });

    //设置vip
    router.all('/api/setvip',function(req,res){
        var vip = req.param("vip");
        var user_id = req.param("user_id");

        var params = {
            vip:vip,
            method:'PUT'
        };

        Action.send(req,res,'users/'+user_id,params,function(res,data){

            var json=JSON.parse(data);

            //console.log(json);

            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    });

    //体检列表
    router.all('/api/testtemps/list',function(req,res){
        var page = req.param("page");
        var rows = req.param("rows");

        var params = {
            page:page,
            rows:rows,
            method:'GET'
        };
        //console.log(params);
        Action.send(req,res,'testtempletes/list',params,function(res,data){

            var json=JSON.parse(data);
            //console.log(json.data);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    });

    //新增体检模板
    router.all('/api/testtemps',function(req,res){

        var testtemp_name = req.param("testtemp_name");  //模板名称
        var testtemp_days = req.param("testtemp_days");          //几天后体检
        var testtemp_attention = req.param("testtemp_attention");//注意事项
        var testtemp_introduction = req.param("testtemp_introduction"); //模板介绍


        var params = {
            testtemp_name:testtemp_name,
            testtemp_days:testtemp_days,
            testtemp_attention:testtemp_attention,
            testtemp_introduction:testtemp_introduction
        };

        Action.send(req,res,'/testtempletes',params,function(res,data){


            var json=JSON.parse(data);

            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    });

    //体检详情
    router.all('/api/tests',function(req,res){

        var id = req.param("id");  //模板名称

        var params = {
            id:id,
            method:'GET'
        };

        Action.send(req,res,'testtempletes/'+id,params,function(res,data){

            var json=JSON.parse(data);

            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    });

    //修改体检模板
    router.all('/api/testtemps/edit',function(req,res){

        var id=req.param("id");
        var testtemp_name = req.param("testtemp_name");  //模板名称
        var testtemp_days = req.param("testtemp_days");          //几天后体检
        var testtemp_attention = req.param("testtemp_attention");//注意事项
        var testtemp_introduction = req.param("testtemp_introduction"); //模板介绍

        var params = {
            testtemp_name:testtemp_name,
            testtemp_days:testtemp_days,
            testtemp_attention:testtemp_attention,
            testtemp_introduction:testtemp_introduction,
            method:'PUT'
        };

        Action.send(req,res,'testtempletes/'+id,params,function(res,data){

            var json=JSON.parse(data);

            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    });

    //删除模板
    router.all('/api/testtemps/delete',function(req,res){

        var id=req.param("id");
        var param={};
        param["method"]="DELETE";

        Action.send(req,res,'testtempletes/'+id,param,function(res,data){

            var json=JSON.parse(data);

            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    });


    //管理员列表
    router.all('/api/admin/list',function(req,res){
        var page = req.param("page");
        var rows = req.param("rows");

        var params = {
            page:page,
            rows:rows,
            method:'GET'
        };

        Action.send(req,res,'admin/list',params,function(res,data){

            var json=JSON.parse(data);
            //console.log(json.data.rows[3].roleSet);

            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    });

    //管理员新增
    router.all('/api/admin/add',function(req,res){
        var admin_name = req.param("admin_name");
        var admin_phone = req.param("admin_phone");
        var admin_password = req.param("admin_password");
        var roleids = req.param("roleids");
        var admin_id=req.param("admin_id");

        var params = {
            admin_name:admin_name,
            admin_phone:admin_phone,
            admin_password:admin_password,
            admin_id:admin_id,
            roleids:roleids
        };

        Action.send(req,res,'admin',params,function(res,data){

            var json=JSON.parse(data);

            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    });

    //管理员详情
    router.all('/api/admin/detail',function(req,res){

        var id = req.param("id");

        var params = {
            method:"GET"
        };

        Action.send(req,res,'admin/'+id,params,function(res,data){

            var json=JSON.parse(data);

            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    });

    //管理员修改
    router.all('/api/admin/edit',function(req,res){

        var admin_name = req.param("admin_name");
        var admin_phone = req.param("admin_phone");
        var roleids = req.param("roleids");
        var admin_id = req.param("admin_id");
        var id=req.param("id");

        var params = {
            admin_name:admin_name,
            admin_phone:admin_phone,
            roleids:roleids,
            admin_id:admin_id,
            method:"PUT"
        };

        Action.send(req,res,'admin/'+id,params,function(res,data){

            var json=JSON.parse(data);

            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    });

    //管理员删除
    router.all('/api/admin/delete',function(req,res){

        var admin_id=req.param("admin_id");
        var id=req.param("id");
        var param={};
        param["method"]="DELETE";
        param["admin_id"]=admin_id;

        Action.send(req,res,'admin/'+id,param,function(res,data){

            var json=JSON.parse(data);

            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    });


    //栏目新增
    router.all('/api/artcate/add',function(req,res){

        var catenames=req.param("catenames");

        var param={};
        param["catenames"]=catenames;

        Action.send(req,res,'/artcate',param,function(res,data){

            var json=JSON.parse(data);

            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    });

    //栏目修改
    router.all('/api/artcate/edit',function(req,res){

        var catename=req.param("catename");
        var id=req.param("id");

        var param={};
        param["name"]=catename;
        param["method"]='PUT';

        console.log(param);

        Action.send(req,res,'artcate/'+id,param,function(res,data){

            var json=JSON.parse(data);

            console.log(json);

            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    });

    //栏目删除
    router.all('/api/artcate/delete',function(req,res){

        var id=req.param("id");
        var admin_id=req.param("admin_id");

        var param={};
        param["method"]='DELETE';
        param["admin_id"]=admin_id;

        Action.send(req,res,'artcate/'+id,param,function(res,data){

            var json=JSON.parse(data);

            //console.log(json);

            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    });

    //文章列表
    router.all('/api/articles/list',function(req,res){
        var cate_id=req.param("cate_id");
        var page = req.param("page");
        var rows = req.param("rows");
        var params = {
            page:page,
            rows:rows,
            cate_id:cate_id,
            method:'GET'
        };

        Action.send(req,res,'article/list',params,function(res,data){

            var json=JSON.parse(data);
            //console.log(json.data);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    });

    //新增文章
    router.all('/api/articles/add',function(req,res){
        var cate_id=req.param("cate_id");
        var article_title = req.param("article_title");
        var article_pic = req.param("article_pic");
        var article_content = req.param("article_content");
        var article_from = req.param("article_from");
        var params = {
            article_title:article_title,
            article_pic:article_pic,
            cate_id:cate_id,
            article_content:article_content,
            article_from:article_from,
            method:'POST'
        };

        Action.send(req,res,'article',params,function(res,data){

            var json=JSON.parse(data);
            //console.log('yudan', json.data);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    });

    //发布文章
    router.all('/api/articles/publish',function(req,res){
        var admin_id=req.param("admin_id");
        var article_publish = req.param("article_publish");
        var article_id = req.param("article_id");

        var params = {
            admin_id:admin_id,
            article_publish:article_publish,
            method:'PUT'
        };

        Action.send(req,res,'article/'+article_id,params,function(res,data){

            var json=JSON.parse(data);
            //console.log('yudan', json.data);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    });

    //文章详情
    router.all('/api/articles/detail',function(req,res){
        var article_id = req.param("article_id");
        var params = {
            method:'GET'
        };

        Action.send(req,res,'article/'+article_id,params,function(res,data){

            var json=JSON.parse(data);
            //console.log('yudan', json.data);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json.data));
            }else{
                res.status(200).send(data);
            }
        })
    });

    //文章修改
    router.all('/api/articles/edit',function(req,res){

        var cate_id=req.param("cate_id");
        var article_title = req.param("article_title");
        var article_pic = req.param("article_pic");
        var article_content = req.param("article_content");
        var article_from = req.param("article_from");
        var article_id = req.param("article_id");
        var params = {
            article_title:article_title,
            article_pic:article_pic,
            cate_id:cate_id,
            article_content:article_content,
            article_from:article_from,
            method:'PUT'
        };

        Action.send(req,res,'article/'+article_id,params,function(res,data){

            var json=JSON.parse(data);
            //console.log('yudan', json.code);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    });

    //文章删除
    router.all('/api/articles/delete',function(req,res){

        var article_id=req.param("article_id");
        var admin_id = req.param("admin_id");

        var params = {
            method:'DELETE',
            admin_id:admin_id
        };

        Action.send(req,res,'article/'+article_id,params,function(res,data){

            var json=JSON.parse(data);

            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    });

    //医生申请列表
    router.all('/api/doctorApplieslist',function(req,res){
        var page = req.param("page");
        var rows = req.param("rows");
        var realname=req.param("realname");
        var status=req.param("status");
        var params = {
            page:page,
            rows:rows,
            realname:realname,
            status:status,
            method:"GET"
        };

        Action.send(req,res,'doctorApplieslist',params,function(res,data){
            //console.log(data);
            var json=JSON.parse(data);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    });

    //医生列表
    router.all('/api/doctorlist',function(req,res){
        var is_top=req.param("is_top");
        var page = req.param("page");
        var rows = req.param("rows");
        var doctor_type_id=req.param("doctor_type_id");//医生类别id
        var realname=req.param("realname");//医生名
        var params = {
            page:page,
            rows:rows,
            doctor_type_id:doctor_type_id,
            realname:realname,
            is_top:is_top,
            method:"GET"
        };
        Action.send(req,res,'doctorslist',params,function(res,data){

            var json=JSON.parse(data);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    });

    //医生详情
    router.all('/api/doctorDetails',function(req,res){
        var doctor_id=req.param("doctor_id");//医生类别id
        var params={};
        params["method"]="GET";
        params["user_id"]=0;
        Action.send(req,res,'/doctors/'+doctor_id,params,function(res,data){
            var json=JSON.parse(data);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    });

    //医生申请详情
    router.all('/api/doctor_applies',function(req,res){

        var doctorapply_id=req.param("doctorapply_id");//医生类别id
        var param={};
        param["method"]="GET";
        Action.send(req,res,'/doctor_applies/'+doctorapply_id,param,function(res,data){

            var json=JSON.parse(data);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    });

    //医生申请审核
    router.all('/api/doctor_applies_Auditing',function(req,res){

        var doctorapply_id=req.param("doctorapply_id");//医生申请id
        var param={};
        param["method"]="PUT";
        param["status"]=req.param("status");
        param["remark"]=req.param("remark");
        param["doctor_type_id"]=req.param("doctor_type_id");
        param["newcard_ability"]=req.param("newcard_ability");
        // console.log(param);
        Action.send(req,res,'/doctor_applies/'+doctorapply_id,param,function(res,data){
            var json=JSON.parse(data);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    });
    //热榜置顶&取消热榜
    router.all('/api/hot_list',function(req,res){
        var act_id = req.param("act_id");
        var top=req.param("top");
        var params={};
        params["method"]="PUT";
        params["top"]=top;
        Action.send(req, res,"/doctors/"+act_id,params,function(res,data){
            var json=JSON.parse(data);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    });
    //新增名医
    router.all('/api/doctors/famous',function(req,res){

        var params={};
        params["realname"]=req.param("realname");
        params["password"]=req.param("password");// 初始密码
        params["idcard"]=req.param("idcard");//身份证号
        params["bankcard"]=req.param("bankcard");//银行卡号
        params["province_id"]=req.param("province_id");//省
        params["city_id"]=req.param("city_id");//市
        params["area_id"]=req.param("area_id");//区
        params["hospital_id"]=req.param("hospital_id");//医院全称
        params["department_id"]=req.param("department_id");//科
        params["depart_phone"]=req.param("depart_phone");//科室电话
        params["duty_id"]=req.param("duty_id");//职称
        params["pic_neg"]=req.param("pic_neg");//手持证件照
        params["pic_pos"]=req.param("pic_pos");//证明免冠照
        params["specialty"]=req.param("specialty");//擅长
        params["introduction"]=req.param("introduction");//个人介绍
        params["phone"]=req.param("phone");//联系电话
        params["method"]="POST";

        Action.send(req, res,"doctorsFamous",params,function(res,data){
            var json=JSON.parse(data);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    });
    //订单列表
    router.all('/api/consults/search',function(req,res){
        var params={};
        params["doctor_id"]=req.param("doctor_id");
        params["hospital_id"]=req.param("hospital_id");
        params["status"]=req.param("status");//咨询状态(1=进行中 2=结束)
        params['page']=1;
        params["method"]="GET";
        //console.log(params);
        Action.send(req, res,"consultsSearch",params,function(res,data){
            var json=JSON.parse(data);//console.log(json.data);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    });

    //医院的列表
    router.all('/96053/api/hostpital',function(req,res){
        var page = req.param('page');
        var rows = req.param('rows');
        var province_id = req.param('province_id');
        var city_id = req.param('city_id');
        var area_id = req.param('area_id');
        var hospital_levelid=req.param('hospital_levelid');
        if(!page)
            page=1;
        if(!rows)
            rows=10;
        if(isNaN(province_id))
            province_id = '';
        if( isNaN(city_id))
            city_id = '';
        if( isNaN(area_id))
            area_id = '';
        if( isNaN(hospital_levelid))
            hospital_levelid = '';
        var param={page:page,rows:rows,province_id:province_id,city_id:city_id,area_id:area_id,hospital_levelid:hospital_levelid};
        param["method"]="GET";

        Action.send(req, res, '/new/hospital/list', param, function (res, data) {
            //console.log("医院列表查询",data);
            var json = JSON.parse(data);
            if (json.code == 0) {
                res.status(200).send(JSON.stringify(json));
            } else {
                res.status(200).send(data);
            }
        })

    });

    //医院详情的数据
    router.get('/api/hosptialdetial',function(req,res){
        var act_id = req.param("act_id");
        //var params = {hospital_id:act_id};
        //console.log("yiyuande can shu",params);
        var params = {};
        params["method"]="GET";
        Action.send(req, res,"/new/hospital/"+act_id,params,function(res,data){
            var json=JSON.parse(data);

            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    });

    //医院详情的注册医生列表
    router.all('/api/hosptialdetial/doctors',function(req,res){
        var hospital_id = req.param("act_id");
        var params = {hospital_id:hospital_id};
        var page = req.param('page');
        var rows = req.param('rows');
        if(!page)
            page=1;
        if(!rows)
            rows=10;
        //console.log("参数",params);
        //var params = {};
        params["method"]="GET";
        params["page"] = page;
        params["rows"] = rows;
        Action.send(req, res,"/new/doctors/list",params,function(res,data){
            var json=JSON.parse(data);
            //console.log("医院详情的医生",data);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    });

    //添加医院
    router.get('/api/addhosptial',function(req,res){
        //var admin_id = req.param("admin_id");
        var hospital_name = req.param("hospital_name");
        var hospital_phone = req.param("hospital_phone");
        var hospital_levelid = req.param("hospital_levelid");
        var province_id = req.param("province_id");
        var city_id = req.param("city_id");
        var area_id = req.param("area_id");
        var departmentStr = req.param("departmentStr");
        var dutyStr = req.param("dutyStr");
        var hospital_pic = req.param("hospital_pic");
        var address = req.param("address");
        var hospital_desc = req.param("hospital_desc");
        var process = req.param("process");
        var newcard_ability = req.param("newcard_ability");
        var params = {hospital_name:hospital_name,hospital_phone:hospital_phone,hospital_levelid:hospital_levelid,
            province_id:province_id,city_id:city_id,area_id:area_id,departmentStr:departmentStr,dutyStr:dutyStr,
            hospital_pic:hospital_pic,address:address,hospital_desc:hospital_desc,process:process,newcard_ability:newcard_ability};
        params["method"]="post";
        // console.log("添加医院的参数",params);
        Action.send(req, res,"/new/hospital",params,function(res,data){
            var json=JSON.parse(data);
            //console.log("添加医院的结果",json);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    });

    //删除医院
    router.all('/api/deletehospital',function(req,res){
        var hospital_id = req.param("act_id");
        var params={};
        params["method"]="DELETE";
        Action.send(req, res,"/new/hospital/"+hospital_id,params,function(res,data){
            var json=JSON.parse(data);
            //console.log("删除医院",json.msg);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    })

    //编辑医院
    router.get('/api/edithosptial',function(req,res){
        var hospital_id = req.param("hospital_id");
        var hospital_name = req.param("hospital_name");
        var hospital_phone = req.param("hospital_phone");
        var hospital_levelid = req.param("hospital_levelid");
        var newcard_ability = req.param("newcard_ability");
        var province_id = req.param("province_id");
        var city_id = req.param("city_id");
        var area_id = req.param("area_id");
        var departmentlist = req.param("departmentlist");
        var dutylist = req.param("dutylist");
        var hospital_pic = req.param("hospital_pic");
        var address = req.param("address");
        var hospital_desc = req.param("hospital_desc");
        var process = req.param("process");
        var params = {hospital_id:hospital_id,hospital_name:hospital_name,hospital_phone:hospital_phone,hospital_levelid:hospital_levelid,
            province_id:province_id,city_id:city_id,area_id:area_id,departmentlist:departmentlist,dutylist:dutylist,hospital_pic:hospital_pic,
            address:address,hospital_desc:hospital_desc,process:process,newcard_ability:newcard_ability};
        params["method"]="put";
        // console.log("编辑医院的发送参数",params);
        Action.send(req, res,"/new/hospital/"+hospital_id,params,function(res,data){
            var json=JSON.parse(data);
            //console.log("编辑医院的结果",json);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    });
    //获得所有医院
    router.all('/api/hospitalsAll',function(req,res){
        var param={};
        param["method"]="GET";
        Action.send(req,res,'hospitalsAll',param,function(res,data){
            var json=JSON.parse(data);
            // console.log(data);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    });

    //医院下所有医生
    router.all('/api/hospitalsAllDoctor',function(req,res){
        var param={};
        param["method"]="GET";
        var hospital_id= req.param("hospital_id");
        Action.send(req,res,"/hospital/"+hospital_id+"/doctors",param,function(res,data){
            var json=JSON.parse(data);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    });

    //未结算资金列表
    router.all('/api/settlementLog/list',function(req,res){

        var doctor_name = req.param("doctor_name");
        var params = {};
        params["method"]="GET";
        params["realname"] = doctor_name;
        var page = req.param('page');
        var rows = req.param('rows');
        if(!page)
            page=1;
        if(!rows)
            rows=10;
        params["page"] = page;
        params["rows"] = rows;
        Action.send(req, res,"settlementLog/list",params,function(res,data){
            var json=JSON.parse(data);
            //console.log("未结算资金列表数据",json);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    });
    //已结算资金列表
    router.all('/api/settlementLog/list/finish',function(req,res){

        //var params = {hospital_id:act_id};
        var month = req.param("month");
        if(isNaN(month)){
            month = '';
        }
        //console.log("month",month);
        var params = {};
        params["month"] = month;
        // console.log(month);
        var page = req.param('page');
        var rows = req.param('rows');
        if(!page)
            page=1;
        if(!rows)
            rows=10;
        params["method"]="GET";
        params["page"] = page;
        params["rows"] = rows;
        Action.send(req, res,"settlementLog/list/finish",params,function(res,data){
            var json=JSON.parse(data);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    });


    //医院下所有科室名称
    router.all('/api/hospitalsAllDepartments',function(req,res){
        var param={};
        param["method"]="GET";
        var hospital_id= req.param("hospital_id");
        Action.send(req,res,"/hospital/"+hospital_id+"/departments",param,function(res,data){
            var json=JSON.parse(data);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    });


    //医院下所有职称名称
    router.all('/api/hospitalsAllDuty',function(req,res){
        var param={};
        param["method"]="GET";
        var hospital_id= req.param("hospital_id");
        Action.send(req,res,"/hospital/"+hospital_id+"/duty",param,function(res,data){
            var json=JSON.parse(data);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    });
    //获得所有医生类别
    router.all('/api/doctorTypeAll',function(req,res){
        var param={};
        param["method"]="GET";
        Action.send(req,res,"doctortypeall",param,function(res,data){
            var json=JSON.parse(data);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    });

    //医生编辑
    router.all('/api/doctorUpdate',function(req,res){
        var doctor_id =req.param("doctor_id");
        var pamars={};
        pamars.realname=req.param("realname");//真实姓名
        pamars.doctor_type_id=req.param("doctor_type_id");//医生等级
        pamars.service_count=req.param("service_count");// 服务单数
        pamars.fans_count=req.param("fans_count");// 粉丝数
        pamars.idcard=req.param("idcard");//身份证号
        pamars.card_num=req.param("card_num");//银行卡号
        pamars.accountBalance=req.param("accountBalance");//当前账户余额
        pamars.province_id=req.param("province_id");//省
        pamars.city_id=req.param("city_id");//市
        pamars.area_id=req.param("area_id");//区
        pamars.hospital_id=req.param("hospital_id");//医院全称
        pamars.department_id=req.param("department_id");//科
        pamars.depart_phone=req.param("depart_phone");//科室电话
        pamars.duty_id=req.param("duty_id");//职称
        pamars.pic_neg=req.param("pic_neg");//手持证件照
        pamars.pic_pos=req.param("pic_pos");//正面免冠照
        pamars.specialty=req.param("specialty");//擅长
        pamars.introduction=req.param("introduction");//个人介绍
        pamars.newcard_ability=req.param("newcard_ability");//建卡能力
        pamars["method"]="PUT";
        Action.send(req,res,"/doctors/"+doctor_id,pamars,function(res,data){
            var json=JSON.parse(data);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    });
    //卡券的列表
    router.all('/api/coupons/list',function(req,res){
        var page = req.param('page');
        var rows = req.param('rows');
        var discount = req.param('discount');
        var status = req.param('status');
        if(!page)
            page=1;
        if(!rows)
            rows=10;
        var params = {};
        params["method"]="GET";
        params["page"] = page;
        params["rows"] = rows;
        if (discount != 'undefined' )
            params["discount"] = discount;
        if (status != 'undefined')
            params["status"] = status;

        //console.log("参数",params);
        Action.send(req, res,"/new/coupon_temps/list",params,function(res,data){
            var json=JSON.parse(data);
            //console.log("卡券数据",data);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })

    });
    //添加卡券
    router.get('/api/addCoupon',function(req,res){

        var coupon_name = req.param("name");
        var dole_start_time = req.param("start_time");
        var dole_end_time = req.param("end_time");
        //var timeLimitStr = req.param("timeLimitStr");
        var limit_count = req.param("AddCouponLimit_count");
        var day = req.param("effective_time");
        var discount = req.param("couponDiscount");
        var totalcount = req.param("couponQuantity");
        var coupon_type = req.param("rangeStr");
        var cost_type = req.param("formStr");
        var price = req.param("price");
        var coupon_desc	 = req.param("couponInstro");
        var coupon_cover = req.param("coupon_pic");
        var day = req.param("effective_time");

        var params = {coupon_name:coupon_name,dole_start_time:dole_start_time,dole_end_time:dole_end_time,
            day:day,limit_count:limit_count,day:day,discount:discount,totalcount:totalcount,coupon_type:coupon_type,
            cost_type:cost_type,price:price,coupon_desc:coupon_desc,coupon_cover:coupon_cover};
        params["method"]="post";
        //console.log("添加卡券的参数",params);
        Action.send(req, res,"/new/coupon_temps",params,function(res,data){
            var json=JSON.parse(data);
            //console.log("添加卡券的结果",json);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    });

    //卡券详情的数据
    router.get('/api/couponDetial',function(req,res){
        var act_id = req.param("act_id");
        //var params = {hospital_id:act_id};
        var params = {};
        params["method"]="GET";
        Action.send(req, res,"/new/coupon_temps/"+act_id,params,function(res,data){
            var json=JSON.parse(data);
            //console.log("卡券详情的数据",json);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    });

    //编辑卡券
    router.get('/api/editCoupon',function(req,res){

        var coupon_temp_id = req.param("coupon_temp_id");
        var coupon_name = req.param("name");
        var dole_start_time = req.param("start_time");
        var dole_end_time = req.param("end_time");
        //var timeLimitStr = req.param("timeLimitStr");
        var limit_count = req.param("CouponLimit_count");
        var day = req.param("effective_time");
        var discount = req.param("couponDiscount");
        var totalcount = req.param("couponQuantity");
        var coupon_type = req.param("rangeStr");
        var cost_type = req.param("formStr");
        var price = req.param("price");
        var coupon_desc	 = req.param("couponInstro");
        var coupon_cover = req.param("coupon_pic");

        var params = {coupon_temp_id:coupon_temp_id,coupon_name:coupon_name,dole_start_time:dole_start_time,dole_end_time:dole_end_time,
            limit_count:limit_count,day:day,discount:discount,totalcount:totalcount,coupon_type:coupon_type,
            cost_type:cost_type,price:price,coupon_desc:coupon_desc,coupon_cover:coupon_cover};
        params["method"]="put";
        //console.log("编辑卡券的参数",params);
        Action.send(req, res,"/new/coupon_temps/"+coupon_temp_id,params,function(res,data){
            var json=JSON.parse(data);
            //console.log("编辑卡券的结果",json);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    });

    //直播列表
    router.all('/api/lives_b/list',function(req,res){
        var doctor_id =req.param("doctor_id");
        var current_date =req.param("current_date");
        var pamars={};
        var page = req.param('page');
        var rows = req.param('rows');
        if(!page)
            page=1;
        if(!rows)
            rows=10;

        if(doctor_id!=-1){
            pamars.doctor_id=doctor_id;//医生id
        }
        pamars.current_date=current_date;//当前时间
        pamars.page=page;
        pamars.rows=rows;
        pamars["method"]="GET";
        Action.send(req,res,"/new/lives/list",pamars,function(res,data){
            var json=JSON.parse(data);
            // console.log(json.data);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(json);
            }
        })
    });
    //直播详情
    router.all('/api/lives',function(req,res){

        var live_id =req.param("live_id");//直播标识
        var pamars={};
        pamars["method"]="GET";
        Action.send(req,res,"/new/lives/"+live_id,pamars,function(res,data){
            var json=JSON.parse(data);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(json);
            }
        })
    });

    //新增直播
    router.all('/api/livesAdd',function(req,res){
        var doctor_id =req.param("doctor_id");//直播医生id
        var datetime =req.param("datetime");//直播日期
        var time=req.param("time");//直播时间段
        var live_title=req.param("live_title");//直播主题
        var live_desc=req.param("live_desc");//直播内容;
        var pamars={};
        pamars.doctor_id=doctor_id;//医生id
        pamars.date=datetime;//当前日期
        pamars.time=time;//当前时间段
        pamars.live_title=live_title;//直播内容
        pamars.live_desc=live_desc;
        pamars["method"]="POST";
        // console.log(pamars);
        Action.send(req,res,"/new/lives",pamars,function(res,data){
            var json=JSON.parse(data);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(json);
            }
        })
    });

    //修改直播
    router.all('/api/livesUpdate',function(req,res){
        var pamars={};
        pamars.live_id=req.param("live_id");//直播标识
        pamars.live_title=req.param("live_title");//直播标题
        pamars.time=req.param("time");//直播时间段
        pamars.date=req.param("date");//直播日期
        pamars.live_desc=req.param("live_desc");//直播内容
        pamars["method"]="PUT";
        // console.log(pamars);
        Action.send(req,res,"/new/lives/",pamars,function(res,data){
            var json=JSON.parse(data);
            if(json.code == 0 ){
                // console.log(json.date);
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(json);
            }
        })

    });

    //删除直播
    router.all('/api/livesDelete',function(req,res){
        var pamars={};
        var live_id=req.param("live_id");//直播标识
        pamars["method"]="DELETE";
        Action.send(req,res,"/new/lives/"+live_id,pamars,function(res,data){
            var json=JSON.parse(data);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(json);
            }
        })

    });
    //家政管理-服务管理-服务类别列表
    router.all('/api/servicetype/list',function(req,res){

        var page = req.param('page');
        var rows = req.param('rows');
        if(!page)
            page=1;
        if(!rows)
            rows=10;
        var params = {
            method:'GET',
            rows:rows,
            page:page
        };

        Action.send(req,res,'/new/servicetype/list',params,function(res,data){

            var json=JSON.parse(data);

            //console.log(json);

            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    });
    //家政管理-家政公司管理-家政公司列表
    router.all('/api/homemaking_company/list',function(req,res){

        var page = req.param('page');
        var rows = req.param('rows');
        var company_name = req.param('company_name');
        if(!page)
            page=1;
        if(!rows)
            rows=10;
        var params = {
            method:'GET',
            rows:rows,
            page:page,
            keyword:company_name
        };

        Action.send(req,res,'/new/homemaking_company/list',params,function(res,data){

            var json=JSON.parse(data);

            //console.log(json);

            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    });
    //家政管理-家政公司管理-家政公司新增
    router.all('/api/homemaking_company',function(req,res){

        var company_name = req.param('company_name');
        var company_phone = req.param('company_phone');
        var address = req.param('address');
        var leader_name = req.param('leader_name');
        var leader_tele = req.param('leader_tele');
        var province_id = req.param('province_id');
        var city_id = req.param('city_id');
        var area_id = req.param('area_id');
        var yuesao = req.param('yuesao');

        var params={
            company_name:company_name,
            company_phone:company_phone,
            address:address,
            leader_name:leader_name,
            leader_tele:leader_tele,
            province_id:province_id,
            city_id:city_id,
            area_id:area_id,
            yuesao:yuesao
        };

        Action.send(req,res,'/new/homemaking_company',params,function(res,data){

            var json=JSON.parse(data);

            //console.log(json);

            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    });
    //家政管理-家政公司管理-家政公司修改
    router.all('/api/homemaking_company_edit',function(req,res){

        var company_name = req.param('company_name');
        var company_phone = req.param('company_phone');
        var address = req.param('address');
        var leader_name = req.param('leader_name');
        var leader_tele = req.param('leader_tele');
        var province_id = req.param('province_id');
        var city_id = req.param('city_id');
        var area_id = req.param('area_id');
        var yuesao = req.param('yuesao');
        var company_id = req.param('company_id');

        var params={
            company_name:company_name,
            company_phone:company_phone,
            address:address,
            leader_name:leader_name,
            leader_tele:leader_tele,
            province_id:province_id,
            city_id:city_id,
            area_id:area_id,
            yuesao:yuesao,
            method:"PUT"
        };

        Action.send(req,res,'/new/homemaking_company/'+company_id,params,function(res,data){

            var json=JSON.parse(data);

            //console.log(json);

            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    });
    //家政管理-家政公司管理-服务人员列表
    router.all('/api/baby_sister/list',function(req,res){

        var page = req.param('page');
        var rows = req.param('rows');
        var company_id = req.param('company_id');
        var keyword = req.param('keyword');
        if(!page)
            page=1;
        if(!rows)
            rows=10;
        if(!keyword)
            keyword='';
        var params = {
            method:'GET',
            rows:rows,
            page:page,
            company_id:company_id,
            keyword:keyword
        };
        //console.log(keyword);
        Action.send(req,res,'/new/baby_sister/list',params,function(res,data){

            var json=JSON.parse(data);

            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    });
    //家政管理-家政公司管理-新增服务人员
    router.all('/api/baby_sister',function(req,res){

        var area_id = req.param('area_id');
        var province_id = req.param('province_id');
        var city_id = req.param('city_id');
        var birth = req.param('birth');
        var valid = req.param('valid');

        var health_creadential = req.param('health_creadential');
        var registered_residence = req.param('registered_residence');
        var degree = req.param('degree');
        var start_work_time = req.param('start_work_time');
        var gongzhong = req.param('gongzhong');

        var weight = req.param('weight');
        var height = req.param('height');
        var cost = req.param('cost');
        var zodiac = req.param('zodiac');
        var phone = req.param('phone');

        var idcard = req.param('idcard');
        var company_id = req.param('company_id');
        var credential_pic = req.param('credential_pic');
        var credential_pic_r = req.param('credential_pic_r');
        var goodat = req.param('goodat');

        var desc = req.param('desc');
        var gender = req.param('gender');
        var first_name = req.param('first_name');
        var second_name = req.param('second_name');

        var params = {
            area_id:area_id,
            province_id:province_id,
            city_id:city_id,
            birth:birth,
            valid:valid,

            health_creadential:health_creadential,
            registered_residence:registered_residence,
            degree:degree,
            start_work_time:start_work_time,
            gongzhong:gongzhong,

            weight:weight,
            height:height,
            cost:cost,
            zodiac:zodiac,
            phone:phone,

            idcard:idcard,
            company_id:company_id,
            credential_pic:credential_pic,
            credential_pic_r:credential_pic_r,
            goodat:goodat,

            description:desc,
            gender:gender,
            first_name:first_name,
            second_name:second_name
        };

        Action.send(req,res,'/new/baby_sister',params,function(res,data){

            var json=JSON.parse(data);

            //console.log(json);

            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    });
    //家政管理-家政公司管理-服务人员详情
    router.all('/api/baby_sister_detail',function(req,res){

        var baby_sister_id = req.param('baby_sister_id');

        var params = {
            baby_sister_id:baby_sister_id,
            method:"GET"
        };

        Action.send(req,res,'/new/baby_sister/'+baby_sister_id,params,function(res,data){

            var json=JSON.parse(data);

            //console.log(json);

            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    });
    //家政管理-家政公司管理-服务人员修改
    router.all('/api/baby_sister_edit',function(req,res){

        var area_id = req.param('area_id');
        var province_id = req.param('province_id');
        var city_id = req.param('city_id');
        var birth = req.param('birth');
        var valid = req.param('valid');

        var health_creadential = req.param('health_creadential');
        var registered_residence = req.param('registered_residence');
        var degree = req.param('degree');
        var start_work_time = req.param('start_work_time');
        var gongzhong = req.param('gongzhong');

        var weight = req.param('weight');
        var height = req.param('height');
        var cost = req.param('cost');
        var zodiac = req.param('zodiac');
        var phone = req.param('phone');

        var idcard = req.param('idcard');
        var company_id = req.param('company_id');
        var credential_pic = req.param('credential_pic');
        var credential_pic_r = req.param('credential_pic_r');
        var goodat = req.param('goodat');

        var desc = req.param('desc');
        var gender = req.param('gender');
        var first_name = req.param('first_name');
        var second_name = req.param('second_name');
        var baby_sister_id = req.param('baby_sister_id');

        var params = {
            method:"PUT",
            area_id:area_id,
            province_id:province_id,
            city_id:city_id,
            birth:birth,
            valid:valid,

            health_creadential:health_creadential,
            registered_residence:registered_residence,
            degree:degree,
            start_work_time:start_work_time,
            gongzhong:gongzhong,

            weight:weight,
            height:height,
            cost:cost,
            zodiac:zodiac,
            phone:phone,

            idcard:idcard,
            company_id:company_id,
            credential_pic:credential_pic,
            credential_pic_r:credential_pic_r,
            goodat:goodat,

            description:desc,
            gender:gender,
            first_name:first_name,
            second_name:second_name
        };
        //console.log(params);

        Action.send(req,res,'/new/baby_sister/'+baby_sister_id,params,function(res,data){

            var json=JSON.parse(data);

            //console.log(json);

            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    });
    //家政订单管理-列表
    router.all('/api/baby_sister_appointment/list',function(req,res){

        var page = req.param('page');
        var rows = req.param('rows');
        var type = req.param('type');
        var company_id = req.param('company_id');
        var status = req.param('status');
        if(!page)
            page=1;
        if(!rows)
            rows=10;
        var params = {
            method:'GET',
            rows:rows,
            page:page,
            type:type,
            company_id:company_id,
            status:status
        };

        Action.send(req,res,'/new/baby_sister_appointment/list',params,function(res,data){

            var json=JSON.parse(data);

            //console.log(json);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    });
    //家政订单管理-详情
    router.all('/api/baby_sister_appointment',function(req,res){

        var baby_sister_appointment_id = req.param('baby_sister_appointment_id');

        var params = {
            method:'GET'
        };

        Action.send(req,res,'/new/baby_sister_appointment/'+baby_sister_appointment_id,params,function(res,data){

            var json=JSON.parse(data);

            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    });
    //家政订单管理-同意或拒绝订单
    router.all('/api/baby_sister_appointment_put',function(req,res){

        var baby_sister_appointment_id = req.param('baby_sister_appointment_id');
        var status = req.param('status');
        var params = {
            method:'PUT',
            status:status
        };

        Action.send(req,res,'/new/baby_sister_appointment/'+baby_sister_appointment_id,params,function(res,data){

            var json=JSON.parse(data);

            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    });
};


